package com.fourforfo.fourmall.cart.config;

import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

@EnableRedisHttpSession
@Configuration
public class FourmallSessionConfig {

    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();

        cookieSerializer.setDomainName("fourmall.com");
        cookieSerializer.setCookieName("FOURMALLSESSION");

        return cookieSerializer;
    }

    /**
     * 使用alibaba提供的Json序列化方式
     * @return
     */
    @Bean
    public RedisSerializer<Object> springSessionRedisSerializer(){

        return new GenericFastJsonRedisSerializer();
    }
}
